﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using TournamentDatabase.Objects;

namespace TournamentDatabase.Rules
{
	class GenderValidationRule : ValidationRule
	{
		bool m_allowUnisex;

		public bool AllowUnisex
		{
			get { return m_allowUnisex; }
			set { m_allowUnisex = value; }
		}

		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
		{
			// Is it a gender?
			if (!(value is Gender))
				return new ValidationResult(false, "Value is not of type Gender.");

			Gender gender = (Gender)value;

			// Do we allow unisex?
			if (!m_allowUnisex)
			{
				if (gender == Gender.Unisex)
					return new ValidationResult(false, "Unisex is not allowed for this input.");
			}

			// Gender is valid
			return new ValidationResult(true, null);
		}

	}
}
